﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class shop_UpdateNews : System.Web.UI.Page
{
    string pictureFilePath;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["keshe2ConnectionString"].ToString();
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            string sql = "SELECT * FROM 通知 WHERE 编号=" + Request.QueryString["编号"].ToString();
            SqlCommand odc = new SqlCommand(sql, conn);
            SqlDataReader odr = odc.ExecuteReader();
            odr.Read();
            txtTitle.Text = odr["标题"].ToString();
            txtContent.Text = odr["内容"].ToString();
            pictureFilePath = odr["图片"].ToString();
            odr.Close();
            conn.Close();
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string connectionString = ConfigurationManager.ConnectionStrings["keshe2ConnectionString"].ToString();
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();
        string sql = "UPDATE 通知 SET 标题='" + txtTitle.Text + "',内容='" + txtContent.Text + "'WHERE 编号=" + Request.QueryString["编号"].ToString();
        SqlCommand odc = new SqlCommand(sql, conn);
        odc.ExecuteNonQuery();
        conn.Close();
        if (fupPicture.HasFile)//图片改变，重新上传图片
        {
            fupPicture.SaveAs(pictureFilePath);
        }
        labMsg.Text = "修改成功！";
        Response.Redirect("~/shop/NewsDetail.aspx?编号="+ Request.QueryString["编号"].ToString());
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/shop/QueryNews2.aspx");
    }
}